package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ConfigHouseBlock;
import com.ruoyi.system.domain.vo.BuildingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ConfigBuildingMapper;
import com.ruoyi.system.domain.ConfigBuilding;
import com.ruoyi.system.service.IConfigBuildingService;

/**
 * 楼栋管理Service业务层处理
 * 
 * @author YuKunXu
 * @date 2024-02-27
 */
@Service
public class ConfigBuildingServiceImpl implements IConfigBuildingService 
{
    @Autowired
    private ConfigBuildingMapper configBuildingMapper;

    /**
     * 查询楼栋管理
     * 
     * @param id 楼栋管理主键
     * @return 楼栋管理
     */
    @Override
    public BuildingVo selectConfigBuildingById(Long id)
    {
        return configBuildingMapper.selectConfigBuildingById(id);
    }

    /**
     * 查询楼栋管理列表
     * 
     * @param configBuilding 楼栋管理
     * @return 楼栋管理
     */
    @Override
    public List<BuildingVo> selectConfigBuildingList(BuildingVo configBuilding)
    {
        return configBuildingMapper.selectConfigBuildingList(configBuilding);
    }

    /**
     * 新增楼栋管理
     * 
     * @param configBuilding 楼栋管理
     * @return 结果
     */
    @Override
    public int insertConfigBuilding(ConfigBuilding configBuilding)
    {
        configBuilding.setCreateTime(DateUtils.getNowDate());
        configBuilding.setCreateBy(SecurityUtils.getUsername());
        return configBuildingMapper.insertConfigBuilding(configBuilding);
    }

    /**
     * 修改楼栋管理
     * 
     * @param configBuilding 楼栋管理
     * @return 结果
     */
    @Override
    public int updateConfigBuilding(ConfigBuilding configBuilding)
    {
        configBuilding.setUpdateTime(DateUtils.getNowDate());
        configBuilding.setUpdateBy(SecurityUtils.getUsername());
        return configBuildingMapper.updateConfigBuilding(configBuilding);
    }

    /**
     * 批量删除楼栋管理
     * 
     * @param ids 需要删除的楼栋管理主键
     * @return 结果
     */
    @Override
    public int deleteConfigBuildingByIds(Long[] ids)
    {
        for (long id : ids){
            int num = hasShop(id);
            if (num > 0){
                return -1;
            } else {
                return configBuildingMapper.deleteConfigBuildingById(id);
            }
        }
        return 0;

    }
    /**
     * 判断楼栋下面是否有商铺， 有商铺则不可删除
     */
    public int hasShop(long id){
        return configBuildingMapper.selectConfigShop(id);
    }

    /**
     * 删除楼栋管理信息
     * 
     * @param id 楼栋管理主键
     * @return 结果
     */
    @Override
    public int deleteConfigBuildingById(Long id)
    {
        return configBuildingMapper.deleteConfigBuildingById(id);
    }
}
